package com.boot.unity.api.modules.training.dao;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.boot.unity.api.modules.training.entity.Region;

@Mapper
public interface RegionDao {

    @Select("select * from training_region t where t.id = #{id}")
    Region getById(Long id);

    @Delete("delete from training_region where id = #{id}")
    int delete(Long id);

    int update(Region region);
    
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into training_region(inscode, seq, name, address, area, type, vehicletype, polygon, totalvehnum, curvehnum, createTime, updateTime) values(#{inscode}, #{seq}, #{name}, #{address}, #{area}, #{type}, #{vehicletype}, #{polygon}, #{totalvehnum}, #{curvehnum}, now(), now())")
    int save(Region region);
    
    int count(@Param("params") Map<String, Object> params);

    List<Region> list(@Param("params") Map<String, Object> params, @Param("offset") Integer offset, @Param("limit") Integer limit);

    @Select("select * from training_region where inscode = #{inscode} and seq = #{seq} limit 1")
    Region getByInscodeAndSeq(@Param("inscode") String inscode, @Param("seq") String seq);

    int updateByInscodeAndSeq(Region region);

    @Delete("delete from training_region where inscode = #{inscode} and seq = #{seq}")
    int deleteByInscodeAndSeq(@Param("inscode") String inscode, @Param("seq") String seq);
}
